package com.baoleme.controller;

import com.baoleme.common.Result;
import com.baoleme.dto.LoginDTO;
import com.baoleme.entity.Member;
import com.baoleme.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuyunbin
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/user")
public class MemberController {

    @Resource
    MemberService memberService;

    @Operation(summary = "用户登录")
    @PostMapping("userLogin")
    public Result<String> login(@RequestBody @Valid LoginDTO loginDTO){
        String token = memberService.login(loginDTO);

        return Result.success(token);


    }

    @Operation(summary = "用户注册")
    @PostMapping("register")
    public Result<Boolean> register(@RequestBody @Valid Member member){

        boolean flag = memberService.saveUser(member);

        return Result.success(flag);


    }

    @Operation(summary = "用户登出")
    @GetMapping("logout")
    public Result<Boolean> logout(String name){

        boolean flag = memberService.logout(name);

        return Result.success(flag);


    }



}
